#include <stdio.h>
#include <mpi.h>
int main(int argc, char **argv)
{
	int i, rank, size, dest;
	int to, src, from, count, tag;
	int st_count, st_source, st_tag;
	double data[100];
	MPI_Status status;
	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	printf("Process %d of %d is alive\n", rank, size);
	dest = size - 1;
	src = 0;
	if (rank == src) {
		to = dest;
		count = 100;
		tag = 2001;
		for (i = 0; i < 100; i++)
			data[i] = i;
		MPI_Send(data, count, MPI_DOUBLE, to, tag, MPI_COMM_WORLD);
	}
	else if (rank == dest) {
		tag = MPI_ANY_TAG;
		count = 100;
		from = MPI_ANY_SOURCE;
		MPI_Recv(data, count, MPI_DOUBLE, from, tag, MPI_COMM_WORLD,
				&status);
		MPI_Get_count(&status, MPI_DOUBLE, &st_count);
		st_source= status.MPI_SOURCE;
		st_tag= status.MPI_TAG;
		printf("Status info: source = %d, tag = %d, count = %d\n",
				st_source, st_tag, st_count);
		printf(" %d received: ", rank);
		for (i = 0; i < st_count; i++)
			printf("%lf ", data[i]);
		printf("\n");
	}
	MPI_Finalize();
	return 0;
}
